﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace YunDrug.Migrations
{
    public partial class _122 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Drug_机构信息");

            migrationBuilder.DropTable(
                name: "Drug_字典项");

            migrationBuilder.DropTable(
                name: "Drug_机构类别");

            migrationBuilder.DropTable(
                name: "Drug_字典信息");

            migrationBuilder.CreateTable(
                name: "Drug_Employees",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    ExtraProperties = table.Column<string>(nullable: true),
                    ConcurrencyStamp = table.Column<string>(maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorId = table.Column<Guid>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierId = table.Column<Guid>(nullable: true),
                    LoginName = table.Column<string>(nullable: true),
                    FullName = table.Column<string>(nullable: true),
                    Describe = table.Column<string>(nullable: true),
                    PassWord = table.Column<string>(nullable: true),
                    OrganName = table.Column<string>(nullable: true),
                    Status = table.Column<bool>(nullable: false),
                    LoginCount = table.Column<int>(nullable: false),
                    LastLoginDateTime = table.Column<DateTime>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Drug_Employees", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Drug_Roles",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    ExtraProperties = table.Column<string>(nullable: true),
                    ConcurrencyStamp = table.Column<string>(maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(nullable: false),
                    CreatorId = table.Column<Guid>(nullable: true),
                    LastModificationTime = table.Column<DateTime>(nullable: true),
                    LastModifierId = table.Column<Guid>(nullable: true),
                    Sort = table.Column<int>(nullable: false),
                    Name = table.Column<string>(nullable: true),
                    Describe = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Drug_Roles", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Drug_EmployeeConfigs",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    EmployeeId = table.Column<Guid>(nullable: false),
                    Code = table.Column<string>(nullable: true),
                    Name = table.Column<string>(nullable: true),
                    Value = table.Column<string>(nullable: true),
                    Describe = table.Column<string>(nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Drug_EmployeeConfigs", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Drug_EmployeeConfigs_Drug_Employees_EmployeeId",
                        column: x => x.EmployeeId,
                        principalTable: "Drug_Employees",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Drug_EmployeeRoles",
                columns: table => new
                {
                    Id = table.Column<Guid>(nullable: false),
                    EmployeeId = table.Column<Guid>(nullable: false),
                    RoleId = table.Column<Guid>(nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Drug_EmployeeRoles", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Drug_EmployeeRoles_Drug_Employees_EmployeeId",
                        column: x => x.EmployeeId,
                        principalTable: "Drug_Employees",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_Drug_EmployeeRoles_Drug_Roles_RoleId",
                        column: x => x.RoleId,
                        principalTable: "Drug_Roles",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Drug_EmployeeConfigs_EmployeeId",
                table: "Drug_EmployeeConfigs",
                column: "EmployeeId");

            migrationBuilder.CreateIndex(
                name: "IX_Drug_EmployeeRoles_EmployeeId",
                table: "Drug_EmployeeRoles",
                column: "EmployeeId");

            migrationBuilder.CreateIndex(
                name: "IX_Drug_EmployeeRoles_RoleId",
                table: "Drug_EmployeeRoles",
                column: "RoleId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "Drug_EmployeeConfigs");

            migrationBuilder.DropTable(
                name: "Drug_EmployeeRoles");

            migrationBuilder.DropTable(
                name: "Drug_Employees");

            migrationBuilder.DropTable(
                name: "Drug_Roles");

            migrationBuilder.CreateTable(
                name: "Drug_机构类别",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    类别名称 = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    类别说明 = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Drug_机构类别", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Drug_字典信息",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    字典名称 = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    排序码 = table.Column<int>(type: "int", nullable: false),
                    文件夹名称 = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    默认字典项编码 = table.Column<Guid>(type: "uniqueidentifier", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Drug_字典信息", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Drug_机构信息",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    机构名称 = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: false),
                    机构类别编码 = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    机构说明 = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: true),
                    机构地址_区域 = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    机构地址_国家 = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    机构地址_所属市 = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    机构地址_省份 = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    机构地址_街道 = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    机构地址_邮政编码 = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Drug_机构信息", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Drug_机构信息_Drug_机构类别_机构类别编码",
                        column: x => x.机构类别编码,
                        principalTable: "Drug_机构类别",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Drug_字典项",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    字典代码 = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    字典信息编码 = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    字典值 = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    排序码 = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Drug_字典项", x => x.Id);
                    table.ForeignKey(
                        name: "FK_Drug_字典项_Drug_字典信息_字典信息编码",
                        column: x => x.字典信息编码,
                        principalTable: "Drug_字典信息",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_Drug_机构信息_机构类别编码",
                table: "Drug_机构信息",
                column: "机构类别编码");

            migrationBuilder.CreateIndex(
                name: "IX_Drug_字典项_字典信息编码",
                table: "Drug_字典项",
                column: "字典信息编码");
        }
    }
}
